<template>
    <div class="login">
        <van-form class="form" @submit="register">
                <div class="avatar">
                    <img src="/assets/images/avatar.png" />
                </div>

                <van-field 
                    v-model="business.mobile"
                    name="mobile"
                    placeholder="手机号码"
                    left-icon="phone-o"
                    required
                    :rules="[
                        { required: true, message: '请填写手机号码' },
                        {pattern: /^1[3-9]\d{9}$/, message: '手机号码格式不正确'}
                    ]"
                />

                <van-field 
                    v-model="business.password"
                    type="password"
                    name="password"
                    placeholder="密码"
                    left-icon="warn-o"
                    required
                    :rules="[{ required: true, message: '请填写密码' }]"
                />

                <div class="button">
                    <van-button round block color="linear-gradient(160deg, #0093E9 0%, #80D0C7 100%)" native-type="submit">注 册</van-button>
                </div>
                    
                <div class="forget">
                    <router-link to="/business/login">前 往 登 录</router-link>
                </div>
        </van-form>
    </div>
</template>

<script setup>
    //获取类似于vue2的this对象
    // proxy == this
    const {proxy} = getCurrentInstance()
    //获取token
    let token = proxy.$route.query.token;
    //创建数据
    let business = ref({
        mobile: '',
        password: ''
    })

    const register = async (values) => 
    {
        // console.log(values)
        // return false
        //接口请求
        var result = await proxy.$POST({
            url: '/business/register',
            params:business.value
        })

        console.log(result)
        if(result.code==0){
            proxy.$fail(result.msg);
            return false;
        }
        //注册成功提醒并跳转
        proxy.$success({
            message: result.msg,
            duration: 1000,
            //关闭回调函数 onClose
            onClose: () => proxy.$router.push(result.url)
        })
    }



</script>


<style scoped>
@import url('/assets/css/login.css');
</style>